/**
 * 画布
 * 砖墙
 */
import config from "../config";
import AbstractCanvas from "./abstract/AbstractCanvas";
import ModelWall from '../model/WallBrick'

/**
 * 画布是单例模式
 * 在一个图层，所以只需要new一个实例即可。
 */
export default new (class extends AbstractCanvas implements ICanvas {
    render(): void {
        // super：调用父类的方法
        super.createModels()
        // 创建己方老巢的墙
        this.createBossWall();
        // 调用渲染模型，防止每次重新渲染时，又生成新的模型实例
        super.renderModels();
    }
    //停止，停止移动
    stop() {
    }
    // 创建己方老巢的墙
    createBossWall() {
        const casW = config.canvas.width
        const casH = config.canvas.height
        const modelW = config.model.common.width
        const modelH = config.model.common.height
        let pos = [
            {x: casW / 2 - modelW * 3, y: casH - modelH},
            {x: casW / 2 - modelW * 3, y: casH - modelH * 2},

            {x: casW / 2 - modelW * 3, y: casH - modelH * 3},
            {x: casW / 2 - modelW * 2, y: casH - modelH * 3},
            {x: casW / 2 - modelW, y: casH - modelH * 3},
            {x: casW / 2, y: casH - modelH * 3},
            {x: casW / 2 + modelW, y: casH - modelH * 3},

            {x: casW / 2 + modelW, y: casH - modelH * 2},
            {x: casW / 2 + modelW, y: casH - modelH},
            {x: casW / 2 + modelW, y: casH},
        ]
        pos.forEach(position => {
            const model = this.model() as ConstructorModel
            const instance = new model(position.x, position.y)
            this.models.push(instance)
        })
    }

    // 抽象方法，返回模型
    model(): ConstructorModel {
        return ModelWall;
    }

    // 抽象方法：返回模型数量
    num(): number {
        return config.wallBrick.num
    }
})('wallBrick')
